home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 184_01 / yanc.c < prev    next >
Text File  |  1980-01-01  |  24KB  |  1,121 lines

  1. /* YANC version 1.0 -- Yet Another New Catalog program */
  2.  
  3. /* Master disk catalog system */
  4. /* Based on the original catalog programs by Ward Christensen */
  5. /* (FMAP, UCAT, CAT, and QCAT) */
  6. /* and incorporating revisions by Lewis Moseley, Jr. */
  7. /* (NEWCAT and CROSSREF) */
  8. /* Rewritten into a single C program for ease of maintainance. */
  9. /* Menu-driven and extended for ease of use. */
  10.  
  11. /* Written by Ken Presser */
  12. /* Converted to BDS-C by David Welch */
  13. /* 06/15/83, Minor corrections and alterations, J.E. Byram */
  14.  
  15. /* Original C dialect...CW/C from The Code Works */
  16. /* Current C dialect...BDS-C from BD Software */
  17.  
  18. #include "bdscio.h"
  19.  
  20. #define LISTCHAR    5    /* bdos function list char to printer */
  21. #define RETURNVER    12    /* bdos function return version no */
  22. #define RESETDISK    13    /* bdos function reset disk system */
  23. #define SELDISK     14    /* bdos function select disk */
  24. #define SRCHFIRST    17    /* bdos function search for first */
  25. #define SRCHNEXT    18    /* bdos function search for next */
  26. #define DELETEFILE    19    /* bdos function delete file */
  27. #define RENAMEFILE    23    /* bdos function rename file */
  28. #define GETDISK     25    /* bdos function get current disk */
  29. #define SETDMA        26    /* bdos function set dma addr */
  30. #define GETALLOC    27    /* bdos function get addr (alloc) */
  31. #define GETDPB        31    /* bdos function get disk parameter *
  32.                  * block address */
  33. #define FCBSIZE     16    /* cpm directory entry size */
  34. #define NUMDRIVES    16    /* number of cpm drives */
  35. #define DIRSIZ        256    /* max # of cpm dir entries */
  36. #define DMADDR        0x80    /* bdos default dma addr */
  37. #define MAXLINES    60    /* max lines before sending FF */
  38. #define FF        0x0c    /* form feed character */
  39. #define CR        0x0d    /* carriage return character */
  40. #define ESC        0x1b    /* escape */
  41.  
  42. #define YES        TRUE
  43. #define NO        FALSE
  44. #define EOS        NO
  45. #define BOOLEAN     int
  46. #define GETS_SIZE    128
  47. #define UP        0xC1
  48. #define DOWN        0xC2
  49. #define HOME        0xC8
  50.  
  51. int    printer;
  52. char    mdrive,ddrive;
  53. char    *pfcb[DIRSIZ],volname[12],ibuffer[BUFSIZ],obuffer[BUFSIZ];
  54. int    nfcb,cfcb,block,remsz,disksz,dirmax,linecount,itemcount;
  55. struct    dontcat {
  56.         char    fname[13];
  57.         struct    dontcat *next;
  58.         } *dcs;
  59. struct    dontcat *head;
  60.  
  61. main()
  62. {
  63.     int i,cmd;
  64.     char matchstr[GETS_SIZE];
  65.  
  66.     if (bdos(RETURNVER,0) == 0) {
  67.         puts("Can't use this program with CP/M 1.4");
  68.         exit();
  69.         }
  70.     mdrive = 'A';
  71.     ddrive = 'B';
  72.     printer = NO;
  73.     while (1) {
  74.         cmd = menu();
  75.         switch (cmd) {
  76.         case 1: updatedir();
  77.             break;
  78.         case 2: strcpy(matchstr,"*.*");
  79.             listmast(matchstr);
  80.             break;
  81.         case 3: getstr(matchstr);
  82.             listmast(matchstr);
  83.             break;
  84.         case 4: getstr(matchstr);
  85.             listvol(matchstr);
  86.             break;
  87.         case 5: dispdir();
  88.             break;
  89.         case 6: initmast();
  90.             break;
  91.         case 7: getdefaults();
  92.             break;
  93.         case 8: makedirfile();
  94.             break;
  95.         case 9: exit();
  96.             break;
  97.         }
  98.     }
  99. }
  100.  
  101. menu()
  102. {
  103.     char x,y;
  104.     char c;
  105.     int i;
  106.  
  107.     clear();
  108.     gotoxy(29,0);
  109.     printf("Master Catalog System");
  110.     gotoxy(5,2);
  111.     printf("Defaults:  ");
  112.     printf("Master Catalog on drive %c:",mdrive);
  113.     printf("  Disk to Add on drive %c:",ddrive);
  114.     gotoxy(16,3);
  115.     printf("Printer: ");
  116.     if (printer)
  117.         printf("on");
  118.     else    printf("off");
  119.     gotoxy(16,5);
  120.     printf("...use arrow keys to move cursor to selection...");
  121.     gotoxy(17,7); revvid(); putchar(' '); norvid(); gotoxy(21,7);
  122.     printf("1) Update the master catalog with above defaults");
  123.     gotoxy(17,9); revvid(); putchar(' '); norvid(); gotoxy(21,9);
  124.     printf("2) List the entire master catalog");
  125.     gotoxy(17,11); revvid(); putchar(' '); norvid(); gotoxy(21,11);
  126.     printf("3) List specific files with a match key");
  127.     gotoxy(17,13); revvid(); putchar(' '); norvid(); gotoxy(21,13);
  128.     printf("4) List a volume from the master catalog");
  129.     gotoxy(17,15); revvid(); putchar(' '); norvid(); gotoxy(21,15);
  130.     printf("5) List the disk directory");
  131.     gotoxy(17,17); revvid(); putchar(' '); norvid(); gotoxy(21,17);
  132.     printf("6) Initialize MAST.CAT");
  133.     gotoxy(17,19); revvid(); putchar(' '); norvid(); gotoxy(21,19);
  134.     printf("7) Update the defaults");
  135.     gotoxy(17,21); revvid(); putchar(' '); norvid(); gotoxy(21,21);
  136.     printf("8) Make directory volume label file");
  137.     gotoxy(17,23); revvid(); putchar(' '); norvid(); gotoxy(21,23);
  138.     printf("9) Quit this program");
  139.     gotoxy(17,7);
  140.     while (1) {
  141.         c = hinchar();
  142.         switch (c) {
  143.         case UP:    getxy(&x,&y);
  144.                 if (y == 7) break;
  145.                 y = y - 2;
  146.                 gotoxy(x,y);
  147.                 break;
  148.         case DOWN:    getxy(&x,&y);
  149.                 if (y == 23) break;
  150.                 y = y + 2;
  151.                 gotoxy(x,y);
  152.                 break;
  153.         case HOME:    gotoxy(17,7);
  154.                 break;
  155.         case CR:    getxy(&x,&y);
  156.                 clear();
  157.                 x = y/2-2;
  158.                 if ( x<1 || x>9 )
  159.                     abort("Invalid menu response = %d"
  160.                         ,x);
  161.                 return x;
  162.                 break;
  163.         }
  164.     }
  165. }
  166.  
  167. updatedir()
  168. {
  169.     char *top;
  170.  
  171.     top = alloc(1);
  172.     printf("\r\nInsert disk to be cataloged in %c:\r\n",ddrive);
  173.     if (mdrive != ddrive)
  174.         printf("Be sure the master disk is in %c:\r\n",mdrive);
  175.     hold();
  176.     readdir();
  177.     if (strcmp(volname,"n/a"))
  178.         updatemast();
  179.     else {
  180.         printf("No volume label file on disk\r\n");
  181.         hold();
  182.         }
  183.     free(top);
  184. }
  185.  
  186. dispdir()
  187. {
  188.     printf("Load disk to list in drive %c:  ",ddrive);
  189.     hold();
  190.     puts("\r\nReading directory...\r\n\n");
  191.     readdir();
  192.     listdir();
  193. }
  194.  
  195. readdir()
  196. {
  197.     char fcb[FCBSIZE];
  198.     char dmapos;
  199.     BOOLEAN firstime;
  200.     char *alloc;
  201.     char *ptr,bsh;
  202.     int i;
  203.  
  204.     bdos(RESETDISK,0);
  205.     bdos(SELDISK,(ddrive-'A'));
  206.     bdos(SETDMA,DMADDR);
  207.     ptr = bdos(GETDPB,0);
  208.     ptr += 2;
  209.     bsh = *ptr;
  210.     block = 1 << (bsh-3);
  211.     ptr += 3;
  212.     disksz = ((*ptr++)+(*ptr++)*256)*block-block;
  213.     remsz = disksz;
  214.     dirmax = (*ptr+(*(ptr+1)*256))+1;
  215.     firstime = YES;
  216.     for (i=0; i<13; i++)
  217.         fcb[i] = '?';
  218.     for (i=13; i<FCBSIZE; i++)
  219.         fcb[i] = '\0';
  220.     nfcb = 0;
  221.     volname[0] = 'n';
  222.     volname[1] = '/';
  223.     volname[2] = 'a';
  224.     volname[3] = EOS;
  225.     while (1) {
  226.         dmapos = bdos(firstime ? SRCHFIRST : SRCHNEXT,fcb);
  227.         if (dmapos == 255) break;
  228.         firstime = NO;
  229.         remsz -= copyentry(DMADDR + 32*(dmapos%4));
  230.         }
  231. }
  232.  
  233. copyentry(fcb)
  234. char *fcb;
  235. {
  236.     int i,j,val;
  237.     char *ptr;
  238.  
  239.     if ((*fcb < 32) && (*(fcb+1) != '-')) {
  240.         ptr = fcb + 1;
  241.         for (i=0; i<11; i++) {
  242.             *ptr = (*ptr) & 0x7f; 
  243.             ++ptr;
  244.             }
  245.         for (i=0; i<nfcb; i++) {
  246.             val = comparefcb(pfcb[i],fcb);
  247.             switch (val) {
  248.             case -2: break;
  249.             case -1: return copyfcb(i,fcb);
  250.                  break;
  251.             case 0: abort("duplicate directory entry\r\n");
  252.                 break;
  253.             case  1: return (*(fcb+15)/(8*block)*block +
  254.                     ((*(fcb+15)%(8*block)>0)*block));
  255.                  break;
  256.             case  2: for (j=nfcb++; j>i; j--)
  257.                     pfcb[j] = pfcb[j-1];
  258.                  pfcb[i] = alloc(FCBSIZE);
  259.                  return copyfcb(i,fcb);
  260.                  break;
  261.                 }
  262.             }
  263.         i = nfcb++;
  264.         pfcb[i] = alloc(FCBSIZE);
  265.         return copyfcb(i,fcb);
  266.         }
  267.     else if ((*fcb < 32) && (*(fcb+1) == '-')) {
  268.         j = 0;
  269.         for (i=2; i<9; i++)
  270.             volname[j++] = fcb[i];
  271.         volname[j++] = ' ';
  272.         for (i=9; i<12; i++)
  273.             volname[j++] = fcb[i];
  274.         volname[j] = EOS;
  275.         return 0;
  276.         }
  277.     else    return 0;
  278. }
  279.  
  280. copyfcb(ptr,fcb)
  281. char *fcb;
  282. int ptr;
  283. {
  284.     char *tfcb,*sfcb;
  285.     int i;
  286.  
  287.     tfcb = sfcb = pfcb[ptr];
  288.     for (i=0; i<FCBSIZE; i++)
  289.         *tfcb++ = *fcb++;
  290.     return (*(sfcb+15)/(8*block)*block +
  291.         ((*(sfcb+15)%(8*block)>0)*block));
  292. }
  293.  
  294. comparefcb(fcb1,fcb2)
  295. char *fcb1,*fcb2;
  296. /* Compare two fcb's  -- return:            *
  297.  *   -2 name1,user1 < name2,user2            *
  298.  *   -1 name1,user1 = name2,user2 & extent1 < extent2;    *
  299.  *    0 name1,user1,extent1 = name2,user2,extent2;    *
  300.  *   +1 name1,user1 = name2,user2 & extent1 > extent2;    *
  301.  *   +2 name1,user1 > name2,user2;            */
  302.  
  303. {
  304.     char s1[14],s2[14];
  305.     int i,k,val;
  306.  
  307.     for (i=0,k=1; k<12; i++,k++) {
  308.         s1[i] = fcb1[k];
  309.         s2[i] = fcb2[k];
  310.         }
  311.     s1[i] = fcb1[0] + '0';
  312.     s2[i] = fcb2[0] + '0';
  313.     i++;
  314.     s1[i] = EOS;
  315.     s2[i] = EOS;
  316.     val = strcmp(s1,s2);
  317.     if (val < 0)
  318.         return -2;
  319.     else if (val > 0)
  320.         return 2;
  321.     else
  322.         if (fcb1[12] < fcb2[12])
  323.             return -1;
  324.         else if (fcb1[12] > fcb2[12])
  325.             return 1;
  326.         else    return 0;
  327. }
  328.  
  329. listdir()
  330. {
  331.     int i,j,k,size;
  332.     char s[50],stemp[5];
  333.     char *fcb;
  334.     
  335.     sprintf(s,"        Directory for Volume: %s\r\n",volname);
  336.     printf("%s",s);
  337.     if (printer) {
  338.         bdos(LISTCHAR,FF);
  339.         for (i=0; i<strlen(s); i++)
  340.             bdos(LISTCHAR,s[i]);
  341.         }
  342.     f